package com.yutel.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBHelper {
	private static Connection conn;
	private static String dbDriverName = "oracle.jdbc.driver.OracleDriver";
	private static String dbUrl = "jdbc:oracle:thin:@133.64.46.199:1522:wttest";
	private static String dbUsername = "nbstest2";
	private static String dbPassword = "nbstest2";

	public static Connection getConn() {
		try {
			Class.forName(dbDriverName);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		try {
			conn = DriverManager.getConnection(dbUrl, dbUsername, dbPassword);
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return conn;
	}

	// 关闭数据库连接
	public static void closeConn(Connection conn) {
		if (null != conn) {
			try {
				conn.close();
			} catch (SQLException e) {

				e.printStackTrace();
			}
		}
	}

	// 测试数据库连接
	public static void main(String[] args) {
		Connection conn = getConn();
		if (conn != null) {
			System.out.println("ok");
		} else {
			System.out.print("error");
		}
	}
}
